package com.hxkj.controller.article;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.UserArticle;
import com.hxkj.service.article.ArticleCollectionService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 文章收藏控制层
 * <p>
 * Created by chenfangzhou on 2018/8/13.
 */
@RestController
@RequestMapping("/article")
public class ArticleCollectionController {

    @Autowired
    private ArticleCollectionService articleCollectionService;


    /**
     * 收藏文章
     */
    @RequestMapping(value = "/collectArticle", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> collectArticle(@ModelAttribute UserArticle userArticle) throws Exception {
        return () -> articleCollectionService.collectArticle(userArticle);
    }

    /**
     * 取消收藏文章
     */
    @RequestMapping(value = "/cancelCollectArticle", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> cancelCollectArticle(@ModelAttribute UserArticle userArticle) throws Exception {
        return () -> articleCollectionService.cancelCollectArticle(userArticle);
    }

    /**
     * 查看文章收藏列表
     */
    @RequestMapping(value = "/getCollectionList", method = RequestMethod.POST)
    public Callable<PageInfo<UserArticle>> getCollectionList(@ModelAttribute UserArticle userArticle , @ModelAttribute PageTo pageParam) throws Exception {
        return () -> articleCollectionService.getCollectionList(userArticle,pageParam);
    }

}
